#include "exptoday.h"
#include "ui_exptoday.h"
#include<QDate>
#include<QDebug>
#include<QDesktopWidget>
#include<QtSql/QSqlQuery>
//This class show records of all current day expenses
ExpToday::ExpToday(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::ExpToday)
{
    ui->setupUi(this);
    QRect q=QApplication::desktop()->availableGeometry(this);
    ui->scrollArea->setGeometry(0,0,(q.width()),(q.height()));
    ui->listWidget->setGeometry(0,50,q.width(),q.height());
    ui->listWidget->setEditFocus(true);
    QAction* backAction = new QAction( tr("Back"), this );
     backAction->setSoftKeyRole( QAction::NegativeSoftKey );
     connect(backAction, SIGNAL(triggered()), this, SLOT(back()));
     addAction( backAction );
     int fontSize=10;
    QDate d;
    d=QDate::currentDate();
    if(db.db_connect())
    {
        QSqlQuery q;
        int count=0;
        q.prepare(QString("select * from expense_table where exp_date=?"));
        q.addBindValue(d);
        if(q.exec())
        {

            while(q.next())
            {
                item1=new QListWidgetItem(QString("%1 : %2").arg(q.value(5).toString()).arg(q.value(1).toDouble()),ui->listWidget,QListWidgetItem::UserType);
                item1->setFont(QFont( "lucida", fontSize, QFont::Normal, FALSE ));
                item1->setToolTip(QString("%1").arg(q.value(0).toString()));
                count++;
            }
        if(count==0)
        {
               ui->listWidget->hide();
              // ui->label->setVisible(false);
              // ui->label_2->setVisible(true);
               ui->label->setText("No Expense recorded for today");


         }
    }//Select

        db.db_close();
    }
}

ExpToday::~ExpToday()
{
    delete ui;
}
void ExpToday::back()
{
    (new ExpView)->show();
}

void ExpToday::on_listWidget_itemActivated(QListWidgetItem* item)
{
    (new ExpDetails(item->toolTip().toInt(),1))->show();
    //Id 1 for today
}
